<extend name="Public/user"/>
<block name="user-right">
<div class="user-right">
	<div class="user-head">
		<h2>{:lang('submit_order')}</h2>
		
	</div>
	<style type="text/css">
		.addedcell{position: relative;}
		.addedcell .delcell{position: absolute;top: 1px;right: 0;display: block;background: red;color: #fff;padding: 2px 10px;height: 16px;line-height: 16px;}
		.listcell{position: relative;}
		.listcell .dellistcell{position: absolute;top: 1px;right: 0;display: block;background: red;color: #fff;padding: 2px 10px;height: 16px;line-height: 16px;}
		#addresslist{display: none;position: relative;}
	</style>

				<div class="fengenav" style="border-top: none;">{:lang('order_info')}</div>
				<div style="padding: 20px;">
					<form action="{:url('User/yubaoinsert')}" method="post">
					<table class="yubao-add" cellpadding="0" cellspacing="0" style="line-height: 20px;">
						<tr>
							<th width="100">{:lang('ex_num')}</th>
							<th width="100">{:lang('baoguo_name')}</th>
							<th width="70">{:lang('jiazhi')}(日元)</th>
							<th width="80">{:lang('baoguo_leixing')}</th>
							<th width="75">原箱/合箱</th>
							<th width="">{:lang('remark')}</th>
						</tr>

						<volist name="yblist" id="v">
							<tr>
								<td>{$v.kuaidi_sn}</td>
								<td>{$v.baoguo_name}</td>
								<td>{$v.jiazhi}</td>
								<td>
									<eq name="v.baoguo_type" value="0">{:lang('common_goods')}</eq>
									<eq name="v.baoguo_type" value="1">{:lang('sensitive_goods')}</eq>
<!-- 									<eq name="v.baoguo_type" value="2">带电池</eq> -->
								</td>
								<td>
									<eq name="v.is_chaibao" value="0">原箱</eq>
									<eq name="v.is_chaibao" value="1">合箱</eq>
								</td>
								<td class="listcell">
									{$v.remark}
									<!-- <a href="###" class="dellistcell">移除</a> -->
								</td>
								<input type="hidden" name="id" value="{$v.id}" class="listid"></tr>
						</volist>

					</table>
				<div class="blank"></div>
				<a href="{:url('User/yubaolist','keyunsong=1')}">{:lang('re_select')}</a>
				<div class="blank"></div>
				<table class="yubao-add" cellpadding="0" cellspacing="0" style="line-height: 20px;">
					<tr>
						<th>{:lang('delivery_address')}</th>
						<th>{:lang('shipping_method')}</th>
					</tr>
					<tr>
						<td style="padding:10px;width: 50%;">
							<div id="defaddress">
								<if condition="$address">
								<div style="margin-bottom: 10px;">
									{:lang('consignee')}：{$address.consignee} &nbsp;&nbsp;{:lang('telphone')}：{$address.tel}<br>
									{:lang('country')}：{$address.areaname} {$address.city}<br>
									{:lang('address')}：{$address.address} ({$address.zipcode}) <br>
								</div>
							</if><input type="hidden" name="addressid" id="addressinputid" value="{$address.id}">
								<a href="###" id="newaddress" style="color:red;">{:lang('check')}{:lang('delivery_address')}</a>
							</div>
							<div id="addresslist">
								<ul>
									<volist name="addresslist" id="v">
										<li style="padding: 5px 0;border-bottom: 1px dashed #dfdfdf;">
											<span style="float: left;display:block;width: 25px;padding: 10px 0;">
												<input type="radio" name="id" value="{$v.id}" class="addressid" <eq name="v.def" value="1">checked</eq>
											>
										</span>
										<span style="float: left;display: block;width: 295px;">
											{$v.consignee} ({$v.tel})&nbsp;{$v.areaname} &nbsp; {$v.address} ({$v.zipcode})
										</span>
										<div class="clear"></div>
									</li>
								</volist>
							</ul>
							<div class="blank"></div>
							<a href="###" class="btnqx addnewaddress">{:lang('new_address')}</a>
							<a href="###" class="btnqd querenaddress">{:lang('confirm_select')}</a>
							<div class="address-form">

								<input type="text" name="consignee"  placeholder="{:lang('consignee')}">
								<div class="blank"></div>
								<input type="text" name="tel"  placeholder="{:lang('mobile')}">
								<div class="blank"></div>
								<select name="areaid" style="width:100%;">
									<option value="0">{:lang('select_country')}</option>
									<volist name=":config('AREA_INFO')" id="v">
										<option value="{$key}">{$v}</option>
									</volist>
								</select>
								<div class="blank"></div>
								<textarea name="address" placeholder="{:lang('city_street')}" style="width: 96%;padding: 2%;"></textarea>
								<div class="blank"></div>
								<input type="text" name="zipcode" placeholder="{:lang('zipcode')}">
								<div class="blank"></div>
								<div style="">
									<button type="button" class="btnqx quxiaoaddaddress">{:lang('cancel')}</button>
									<button type="button" class="btnqd querenaddaddress">{:lang('confirm_address')}</button>
								</div>

							</div>
							</div>
						</td>
						<td style="padding:10px 20px;width: 50%;">
							<if condition="$delivery">
								<volist name="delivery" id="d">
									<div><input type="radio" name="deliveryid" <eq name='key' value='0'>checked</eq>  value="{$d.id}"> &nbsp;{$d.dname} (<a href="{$d.uri}" target="_blank">{:lang(official_website)}</a>)</div>
								</volist>
								<else />
								{:lang('select_address_first')}
							</if>
						</td>
						
					</tr>
					<tr>
					<td colspan="2" style="padding:10px;">
							 <input type="checkbox" name="yunfei"   value="1" >同意直接扣除运费快速发货（余额大于{:config('ZHUANYUN_LOW_YUNFEI')}日元）
							 
							 <br>
						
					 <b style="color:red;">选择增值服务：</b>
					 <input type="radio" name="jiagu"  checked="checked" value="-1" >无需加固（0日元）
					 <input type="radio" name="jiagu"  value="0" >简易加固（{:config('ZHUANYUN_JIAGU_EASY')}日元）
					 <input type="radio" name="jiagu"   value="1" >超级加固（<php>echo C('ZHUANYUN_JIAGU_2')+C('ZHUANYUN_JIAGU_2_LEVEL')</php>日元起，每5kg增加{:config('ZHUANYUN_JIAGU_2_LEVEL')}日元）<br>
					 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
					  &nbsp; &nbsp; &nbsp; &nbsp;<input type="checkbox" name="jiaji"   value="1" >加急（{:config('ZHUANYUN_JIAJI')}日元）|
					   <input type="radio" name="baojia"  id='baojiac'  checked="checked" value="0" >无需保价
					 <input type="radio" name="baojia" id='baojiac'  value="1"  >保价（{:config('ZHUANYUN_BAOJIA')}日元）<br>
					  <b style="color:red;">{:lang('all_jiazhi')}</b>：<input type="text" onkeyup="baojiafei();"   style='width: 10%;border:dotted  #009;' id='allshenbao' name='allshenbao' value='0.00'> 日元
					 
					 预计保价费：<span id='baojiafei'>0.00</span>&nbsp;(日元)
					 </td>
					</tr>
					<tr>
						<td colspan="2" style="padding: 10px;"><span style="float:left;">{:lang('remark')}：</span><textarea name="remark" style="width: 90%;height: 50px;float: left;padding: 5px;" id="dingdanremark" placeholder="{:lang('remark')}"></textarea></td>
					</tr>
				</table>
				<div class="blank"></div>
				<div style="width: 400px;float: right;"><button type="button" class="btnqd tijiaodingdan">{:lang('submit_order')}</button></div>
				<div class="blank"></div>
				</form>
			</div>

</div>
<script type="text/javascript">


function baojiafei(){
	if($('input[name="baojia"]:checked').val()==0){
		return ;
	}
	var deliveryid=$('input[name="deliveryid"]:checked').val();
	if(!deliveryid){
		$.thinkbox.error('请选择您的运送方式！');
	}else{
		var allbaojia=0;
		var allshenbao=$('#allshenbao').val();
		if(allshenbao>130000){
			$('#allshenbao').val(130000);
			$.thinkbox.error('申报价格不能超过130000');
		}
		if(deliveryid!=8){
			allbaojia=400+allbaojia;
		}
		if(allshenbao>20000){
			allbaojia=allbaojia+(Math.ceil((allshenbao-20000)/20000))*{:config('ZHUANYUN_BAOJIA')};
		}
		$('#baojiafei').html(allbaojia+'.00');
	}
}

$("input[name=deliveryid]").click(function(){
	baojiafei();
});
$("input[id=baojiac]").click(function(){
	if($('input[name="baojia"]:checked').val()==1){
		baojiafei();
	}
});
	$(function(){
		$('.tijiaodingdan').click(function(){
			var addressid=$('#addressinputid').val();
			var deliveryid=$('input[name="deliveryid"]:checked').val();
			
			if($('.sel-id').val() == undefined ){
				alert('包裹列表为空不能提交订单!');
				return;
			}
			
			if($('input[name="yunfei"]:checked').val()){
				var yunfei=$('input[name="yunfei"]:checked').val();
				if({$member.available_predeposit}<={:config('ZHUANYUN_LOW_YUNFEI')}){
					alert('您的余额不足'+{:config('ZHUANYUN_LOW_YUNFEI')}+'，无法选择该项服务！');
					return;
				}
			}else{
				var yunfei=0;
			}
			if($('input[name="jiaji"]:checked').val()){
				var jiaji=$('input[name="jiaji"]:checked').val();
			}else{
				var jiaji=0;
			}
			if($('input[name="baojia"]:checked').val()){
				var baojia=$('input[name="baojia"]:checked').val();
			}else{
				var baojia=0;
			}
			var jiagu=$('input[name="jiagu"]:checked').val();
			var remark=$('#dingdanremark').val();
			var allshenbao=$('#allshenbao').val();
			$.post("{:url('')}",{'addressid':addressid,'deliveryid':deliveryid,'remark':remark,'pay_yunfei':yunfei,'fuwu_jiaji':jiaji,'fuwu_baojia':baojia,'fuwu_jiagu':jiagu,'allshenbao':allshenbao},function(data){
				if (data.status) {
					$.thinkbox.success(data.info);
					setTimeout(jumpurl(data.url),1000);
				}else{
					$.thinkbox.error(data.info);
				};
			});
		})

		$('.dellistcell').click(function(){
			var id=$(this).parent().parent().find('.listid').val();
			$.post("{:url('User/yubaocartdel')}",{'id':id},function(data){
				if (data.status) {
					$('.listid').each(function(){
						if (data.info==$(this).val()) {
							$(this).parent().remove();
						};
					})
				}else{
					$.thinkbox.error(data.info);
				};
			});
		})
		$('#newaddress').click(function(){
			$(this).parent().hide();
			$(this).parent().next().show();
		})
		$('.querenaddress').click(function(){
			var id=$('.addressid:checked').val();
			$.post("{:url('User/changeaddress')}",{'id':id},function(data){
				if (data.status) {
					$.thinkbox.success(data.info);
					setTimeout('location.reload()',700);
				};
			})
		})
		$('.addnewaddress').click(function(){
			$(this).parent().find('.address-form').show();
		})
		$('.quxiaoaddaddress').click(function(){
			$(this).parents('.address-form').hide();
		})
		$('.querenaddaddress').click(function(){
			var consignee=$(this).parents('.address-form').find('input[name="consignee"]').val();
			var tel=$(this).parents('.address-form').find('input[name="tel"]').val();
			var areaid=$(this).parents('.address-form').find('select[name="areaid"]').val();
			var address=$(this).parents('.address-form').find('textarea[name="address"]').val();
			var zipcode=$(this).parents('.address-form').find('input[name="zipcode"]').val();
			$.post("{:url('User/addressadd')}",{'consignee':consignee,'tel':tel,'areaid':areaid,'address':address,'zipcode':zipcode},function(data){
				if (data.status) {
						$.thinkbox.success(data.info);
						setTimeout('location.reload()',700);
					}else{
						$.thinkbox.error(data.info);
					};
			})
		})

	})
</script>
</block>